public class demo6 {
    public static void main(String[] args) {
        String s = "ANQNANBNQNANQNQNBNINQNQNANQNINANQNANBNQNANQNQNBNBNQNQNANQNINANQNANBNQNANQNQNBNINQNQNANQNINBNQNANBNQN";
        int ret=0;
        String x="";
        for (int i = 0; i < s.length(); i++) {
            for (int j = i; j <= i + 10; j++) {
                 if (j>s.length())break;
                String temp = s.substring(i, j);
                int sum=Ssum(s,temp);
                if (sum*(j-i)>ret) {
                    ret = Math.max(ret, sum * (j - i));
                    x=temp;
                }
            }
        }
        System.out.println(ret);
        System.out.println(x.toString());
    }
    public static int Ssum(String s,String temp){
        int x=temp.length();
        int sum=0;
        for (int i = 0; i <s.length() ; i++) {
            if (i+x>s.length())break;
            String ret=s.substring(i,i+x);
            if (temp.equals(ret)){
             sum++;
            }
        }
        return sum;
    }
}
